<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 * @version		$Id:$
 */
?>
<?php if (isset($this->controllers) && $this->controllers) : ?>
<?php foreach ($this->controllers as $index => $controller) : ?>
<?php if ($index > 0 && $index % 3 == 0) : ?>
<div class="clear"></div>
<?php endif; ?>
<div class="col w33">
	<div class="content">
		<div class="box header mb0">
			<div class="head"><div></div></div>
			<h2 class="g_a_breadcump">
				<a class="fl" href="javascript: void(0);"><?php echo $this->TRANSLATOR->translator('permission_' . $controller['controller_id'], $controller['module_id']); ?></a>
				<div class="clear"></div>
			</h2>
		</div>
	</div>
	<div class="content">
		<div class="desc">
			<div class="body">
				<?php if ($controller['actions']) : ?>
				<?php $fullTemp = array('role_name' => 'role_' . $this->role['role_id'], 'allow' => 1, 'module_controller' => null, 'action_id' => null); ?>
				<ul>
					<?php foreach ($controller['actions'] as $action) : ?>
					<?php $allowTemp = array('role_name' => 'role_' . $this->role['role_id'], 'allow' => 1, 'module_controller' => $controller['module_id'] . ':' . $controller['controller_id'], 'action_id' => $action['action_id']); ?>
					<?php $denyTemp = array('role_name' => 'role_' . $this->role['role_id'], 'allow' => 0, 'module_controller' => $controller['module_id'] . ':' . $controller['controller_id'], 'action_id' => $action['action_id']); ?>
					<li>
						<p class="fl col w8"><?php echo $this->TRANSLATOR->translator(sprintf('permission_%s_%s', $controller['controller_id'], $action['action_id']), $controller['module_id']); ?></p>
						<p class="fr">
							<input<?php if (in_array($allowTemp, $this->dbRules) || (!in_array($denyTemp, $this->dbRules) && in_array($fullTemp, $this->dbRules))) : ?> checked="checked"<?php endif; ?> type="checkbox" name="actions[]" value="<?php echo $controller['module_id']; ?>_<?php echo $controller['controller_id']; ?>_<?php echo $action['action_id']; ?>" />
						</p>
						<div class="clear"></div>
					</li>
					<?php endforeach; ?>
				</ul>
				<?php endif; ?>
			</div>
		</div>
		<div class="body_footer">
			<div class="bottom_left"><div class="bottom_right"></div></div>
		</div>
	</div>
</div>
<?php endforeach; ?>
<script type="text/javascript">
$(document).ready(function() {
	$('.gCorePermissionRoleSave').unbind('click').click(function() {
		/**
		 * Show g_a_ajax_loading element
		 */
		$('#g_a_ajax_loading').show();
		
		$.ajaxq('core_permission_role_save', {
			type: 'post',
			url: '<?php echo $this->url('core_permission_role', $this->role); ?>?act=save',
			data: $('input[name="actions[]"]').serialize() + '&mod=<?php echo $this->mod; ?>',
			success: function(response) {
				if (response == 'RESULT_OK') {
					Gio.Message.success('<?php echo $this->STRING->escape($this->TRANSLATOR->translator('permission_actions_role_success')); ?>');
				} else {
					Gio.Message.error('<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_error_message')); ?>');
				}
				/**
				 * Hide g_a_ajax_loading element
				 */
				$('#g_a_ajax_loading').hide();
			}			
		});
	});
});
</script>
<?php else : ?>
<div class="g_a_data_notfound"><?php echo $this->TRANSLATOR->translator('common_data_notfound'); ?></div>
<script type="text/javascript">
$(document).ready(function() {
	$('.gCorePermissionRoleSave').unbind('click');
});
</script>
<?php endif; ?>
<div class="clear"></div>